// .txt

beginzonescript;

variables;

short im_hostile = 0;
short last_abil;
short counter = 0;
short set_ter1 = 0;

body;

beginstate INIT_STATE;
	last_abil = get_current_tick();

	if (gf(0,11) > 0) {
		erase_char(0);
		erase_char(1);
		}
		
	if (gf(9,11) == 0) {
		erase_char(30001);
		erase_char(30002);
		erase_char(30003);
		erase_char(30004);
		erase_char(30005);
		erase_char(30006);
		}

	// stonehouse
	sf(0,24,0);
	sf(0,25,0);
	sf(0,26,0);
	sf(0,27,0);
		
	set_name(2,"General Miranda");
	set_name(3,"General Miranda");
	set_name(46,"Chief Cestus");
	set_name(47,"Sage Harlan");
	set_name(48,"Stonehouse");
	
	if (gf(0,12) > 0)
		erase_char(2);

//	set_attack_range(,);

//	add_ability(short which_char_or_group,short which_slot,short which_ability,0);

//	if (is_town_clear(ME))
//		clean_up_town();

	// set up judgments
	if (judgment_convo() == 1) {
		spawn_creature(49);
		set_name(49,"Dastan");
		}
	if (judgment_convo() == 2) {
		spawn_creature(50);
		set_name(50,"Head Jadyra");
		}
	if (judgment_convo() == 3) {
		spawn_creature(51);
		set_name(51,"Head Kuanysh");
		}
	if (judgment_convo() == 4) {
		spawn_creature(52);
		set_name(52,"Jansulu");
		}
	if (judgment_convo() == 5) {
		spawn_creature(53);
		set_name(53,"Sage Aledra");
		}
	if (judgment_convo() == 6) {
		spawn_creature(54);
		set_name(54,"Shaytham");
		}
	if (judgment_convo() == 7) {
		spawn_creature(55);
		set_name(55,"Talant");
		}
	if (judgment_convo() == 8) {
		spawn_creature(56);
		set_name(56,"Geld Nas Assassin");
		}
	if (judgment_convo() == 9) {
		spawn_creature(57);
		set_name(57,"Altynay");
		}

	if ((gf(80,12) > 5) && (gf(2,23) == 0))
		sf(2,23,1);
	if (gf(2,23) > 0)
		set_terrain(0,31,29,0);
		
	// mirror and judgment
	sf(0,15,0);
	sf(0,28,0);
	
	sf(2,19,0);
	break;

beginstate EXIT_STATE;

break;

beginstate START_STATE;
	// kludgy flag corrections
	if ((gf(15,11) > 7) && (gf(80,8) < 6))
		sf(80,8,6);
	if ((gf(31,11) >= 4) && (gf(80,10) < 4))
		sf(80,10,4);
		
		
	if ((gf(0,2) > 0) && (is_talking() == FALSE) && (gf(0,13) == 0)) {
		sf(0,13,1);
		assert_hint(5);
		end();
		}

	// shift miranda
	if ((gf(0,11) >= 2) && (char_ok(3) == FALSE) ) {
		spawn_creature(3);
		set_name(3,"General Miranda");
		}

	// first xp
	if ((gf(2,25) == 1) && (is_talking() == FALSE)) {
		sf(2,25,2);
		award_party_xp(280);
		}
		else if (gf(2,25) == 2) {
			sf(2,25,3);
			assert_hint(11);
			}

	//if ((set_ter1 == 0) && (gf(0,0) > 0)) {
	//	set_ter1 = 1;
	//	set_terrain(,,,);
	//	}
		
	if (gf(0,11) == 0) {
		if (get_ran(1,0,100) < 20)
			give_char_text_bubble(2,"We need you out there.");
		if (get_ran(1,0,100) < 20)
			give_char_text_bubble(2,"I have your report.");
		if (get_ran(1,0,100) < 20)
			give_char_text_bubble(2,"We need you out there.");
		}
	if (gf(0,11) < 12) {
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(46,"Speak with Miranda.");
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(46,"Miranda can guide you.");
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(70,"Miranda can guide you.");
		
		}
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(46,"We did our best.");
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(46,"This is Haven's land.");
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(46,"I will retire soon.");
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(46,"Thank you for your help.");
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(47,"Our knowledge is yours.");
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(47,"I will learn about the Ro.");
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(47,"The Rokaj is very complex.");
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(47,"Nice to see you again.");
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(48,"I exist to serve.");
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(48,"So good to see you.");
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(48,"What do you wish?");
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(48,"A drink perhaps?");
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(48,"Freshen up your haircut?");


	// Miranda
	if (gf(0,11) < 11) {
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(3,"We must rebuild the fort.");
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(3,"I can guide you.");
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(3,"We are under attack.");
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(3,"We need to stabilize.");
		}
		else if (gf(0,11) == 11) {
			if (get_ran(1,0,100) < 20)
				give_char_text_bubble(3,"Go use the portal.");
			}
		else if (gf(0,11) > 11) {
			if (get_ran(1,0,100) < 10)
				give_char_text_bubble(3,"You must make decisions.");
			if (get_ran(1,0,100) < 10)
				give_char_text_bubble(3,"Give me your judgments.");
			if (get_ran(1,0,100) < 10)
				give_char_text_bubble(3,"Meet all of the Raasas.");
			}


	//if (gf(,) < 2) {
	//	inc_flag(,,1);
	//	if (gf(,) == 2)
	//		begin_talk_mode();
	//	}

	//if (((is_combat()) && (tick_difference(last_abil,get_current_tick()) > 0)) || ((is_town()) && (tick_difference(last_abil,get_current_tick()) > 5))) {
	//	last_abil = get_current_tick();
	//	}
break;

beginstate 10;
	if ((gf(1,16) == 0) && (gf(0,11) == 11) && (char_ok(58) == FALSE)) {
		spawn_creature(58);
		set_name(58,"Prince Sutter");
		}
break;

beginstate 11;
	if (char_ok(58)) {
		sf(1,16,1);
		begin_talk_mode(17);
		}
break;

beginstate 12;
break;

beginstate 13;
break;

//	print_str("");
//	set_terrain_string_range(".",1);
//	set_terrain_string_range("The sign says - .",1);
